home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1169 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.6 KB

  1. Path: engnews2.Eng.Sun.COM!usenet
  2. From: nitin@more.eng.sun.com (Nitin More [CONTRACTOR])
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: OO design issue
  5. Date: 09 Jan 1996 18:41:52 GMT
  6. Organization: SunSoft
  7. Message-ID: <NITIN.96Jan9104152@more.eng.sun.com>
  8. References: <4ctp93$2gu@news.kth.se>
  9. NNTP-Posting-Host: more.eng.sun.com
  10. In-reply-to: Anders Olsson's message of 9 Jan 1996 13:06:43 GMT
  11.  
  12.  
  13. I would include vector of Nodes in the Triangle class rather than having
  14. indexes stored there.  Then you don't need to have class TrianglesAndNodes and
  15. whenever you have an handle on the Triangle instance, you immediately have
  16. access to instances of its Nodes.
  17.  
  18. Triangle is made up of 3 Nodes so let the Triangle class keep that
  19. information.  Don't invent another class (TrianglesAndNodes) to keep track of
  20. associations. 
  21.  
  22. -Nitin
  23.  
  24.  
  25. In article <4ctp93$2gu@news.kth.se> Anders Olsson <aolsson@struct.kth.se> writes:
  26.  
  27. > From: Anders Olsson <aolsson@struct.kth.se>
  28. > Newsgroups: comp.lang.c++
  29. > Date: 9 Jan 1996 13:06:43 GMT
  30. > I accidently posted the last message before I got to my point
  31. > (never write messages in a window where you have a "Post it" keycombination:-)
  32. > I'll try again:
  33. >  I have some questions about how to design relations between a class and
  34. >  its member classes.
  35. >  
  36. >  I can simplify my problem to the following three classes:
  37. >  
  38. >  class Node
  39. >  {
  40. >  public:
  41. >     double GetXCoordinate();
  42. >  private:
  43. >     double XCoordinate; 
  44. >  };
  45. >  
  46. >  class Triangle
  47. >  {
  48. >  public:
  49. >     double CalculateArea();
  50. >  private:
  51. >     int nNodeIndex[3]; // Index into node vector
  52. >  };
  53. >  
  54. >  class TrianglesAndNodes
  55. >  {
  56. >    double GetXCoordinate(int NodeNr);
  57. >  private:
  58. >     vector<Node>     NodeVector;   
  59. >     vector<Triangle> TriangleVector;
  60. >  };
  61. >  
  62. > The TrianglesAndNodes class is a world of nodes and triangles, and it contains two vectors of Node:s, and Triangle:s.
  63. > The Triangle has a method that calculates its own area.
  64. > However, it has only information about the index of the nodes it is connected to.
  65. > So to get the necessary coordinates the Triangle instance can use the GetXCoordinate method,
  66. > defined in TrianglesAndNodes. The problem is how to reach the TrianglesAndNodes instance
  67. > from the Triangle instance.
  68. > Is there a recommended way to do this is?
  69. > ---
  70. > Anders Olsson
  71. > Stockholm, Sweden
  72. -- 
  73. ----------------------------------------------------------------------
  74. Nitin More                                                         
  75. SunSoft, Bldg 16  Off: (415) 786 7109                                 
  76. Menlo Park, CA    Fax: (415) 786 7957   e-mail: nitin@more.eng.sun.com
  77. ----------------------------------------------------------------------
  78.